package at.ac.tuwien.dse.health.entity;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * Building where healthcare services are offered and consumed.
 *
 * @author Bernhard Nickel
 * @author Gregor Schauer
 * @author Dominik Strasser
 */
@Entity
@NamedQueries({
		@NamedQuery(name = Hospital.GET_HOSPITAL_NAMES, query = "SELECT name FROM Hospital ORDER BY name"),
		@NamedQuery(name = Hospital.WITH_DEPARTMENT_BY_NAME, query = "SELECT h FROM Hospital h JOIN FETCH h.departments WHERE h.name = :name")
})
public class Hospital implements Serializable {
	public static final String GET_HOSPITAL_NAMES = "Hospital#getHospitalNames";
	public static final String WITH_DEPARTMENT_BY_NAME = "Hospital#withDepartmentByName";
	private Long id;
	private String name;
	private Location location;
	private List<Department> departments;

	@Override
	public String toString() {
		return name;
	}

	@Id
	@GeneratedValue
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Basic(optional = false)
	@Column(unique = true, nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Embedded
	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	@OneToMany
	public List<Department> getDepartments() {
		return departments;
	}

	public void setDepartments(List<Department> departments) {
		this.departments = departments;
	}
}
